/***************************************************************************
   BMP280 humidity, temperature & pressure sensor
 ***************************************************************************/
#ifndef BMP280_H
#define BMP280_H

 #include <Wire.h>
 #include <SPI.h>
 #include <Adafruit_BMP280.h>
 
 Adafruit_BMP280 bmp; // use I2C interface
 Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
 Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();

 float temperature;
 float pressure;
 
 void setup_bmp280() {
   Serial.begin(9600);
   while ( !Serial ) delay(100);   // wait for native usb
   Serial.println(F("BMP280 Sensor event test"));
 
   unsigned status;
   status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
   //status = bmp.begin(0x77);
   if (!status) {
     Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
                       "try a different address!"));
     Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
     Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
     Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
     Serial.print("        ID of 0x60 represents a BME 280.\n");
     Serial.print("        ID of 0x61 represents a BME 680.\n");
     while (1) delay(10);
   }
 
   /* Default settings from datasheet. */
   bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                   Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                   Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                   Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                   Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
 
   bmp_temp->printSensorDetails();

   
    temperature=bmp.readTemperature();
    pressure=bmp.readPressure()/100; //Pa->hPa
 }
 
 void loop_bmp280() {
   //sensors_event_t temp_event, pressure_event;
   //bmp_temp->getEvent(&temp_event);
  // bmp_pressure->getEvent(&pressure_event);
  // temperature=temp_event.temperature;
  // pressure=pressure_event.pressure;

    temperature=bmp.readTemperature();
    pressure=bmp.readPressure()/100; //Pa->hPa
  }

  #endif /* BMP280_H */